<?php

ini_set('memory_limit','16M');

require_once( '/home/cyberpower678/Peachy/Init.php' );

foreach( array( 'cyberbot i', 'commons' ) as $bot ) {
        $site = Peachy::newWiki( $bot );

        if( $bot == "cyberbot i" ) {
                $site->set_runpage("User:Cyberbot I/Run/AR");
        }
        else {
                $site->set_runpage(null);
        }
        
        $admins = $site->allusers( null, array( 'sysop' ) );
        
        if( $bot == "commons" ) print_r($admins);
        
        if( count($admins) < 1000 && $bot == "cyberbot i" ) die();
        if( count($admins) < 5 && $bot == "commons" ) die();
        
        $data = '';
        foreach( $admins as $admin ) {
                $data .= 'adminrights[\''.str_ireplace(
                array(
                        '+',
                        '\\',
                        '\'',
                        '(',
                        ')',
                        '%21',
                        '%2C',
                        '%3A',
                ),
                array(
                        '%20',
                        '\\\\',
                        '%27',
                        '%28',
                        '%29',
                        '!',
                        ',',
                        ':',
                ),
                urlencode($admin['name'])).'\']=1;'."\n";
        }
        if( count($admins) != (count(explode("\n",$data)) - 1) ) { die("Error?"); }
        echo $data;
        
        $page = initPage( "User:Cyberbot I/adminrights-admins.js" );
        $page->edit( $data, 'Updating admins list', true );
}


